<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : "{{ urlfor "RetailController.DataGrid"}}"
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var params = checkQueryTableData(aoData)
			$('#search_key').val() ? params.Filter = $('#search_key').val() : ''
			params.Field = $('#filed').val();
			params.ArcId = {{.m.Id}};
			
			$.post(sSource, JSON.stringify(params),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
			{"mDataProp" : "Id", "bSortable": false}
			,{"data" : "ManualNumber","bSortable": false, render:function(data, type, full, meta) {
				return data + '&nbsp;'+ (full.IsCustomized==1?'<span style="color:red">[定制]</span>':'');	
			}}
			,{"mDataProp" : "TotalMoney"}
			,{"mDataProp" : "ChangesMoney", "bSortable": false}
			,{"mDataProp": "PaymentType", render:function(data, type, full, meta) {
				switch(data){
					case 1:
						return '已付';	
					case 2:
						return '未付';	
				}
				return '';
			}}
			,{"mDataProp" : "SumPayable", "bSortable": false}
			,{"mDataProp" : "BusinessName"}
			,{"mDataProp": "CreatedAt", render:function(data, type, full, meta) {
				return timetransDate(data);	
			}}
			,{"mDataProp": "CreatedBy", "bSortable": false}
			,{"mDataProp": "NowStep", render:function(data, type, full, meta) {
				switch(data){
					case 0:
						return '<span class="am-badge am-badge-primary">待支付</span>';	
					case 1:
						return '<span class="am-badge am-badge-secondary">待加工</span>';	
					case 2:
						return '<span class="am-badge am-badge-success">待取镜</span>';	
					case 3:
						return '<span class="am-badge am-badge-warning">已完成</span>';	
				}
			}} 
			,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"6%",
				"render": function ( data, type, full, meta ) { 
					btns = '<a href="javascript:;" class="am-btn am-btn-success am-btn-xs" onclick="viewRetail('+ full.Id +')">查看</a>';
					return btns;  
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	
	$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});
	
	function viewRetail(id) {
		height = "90%";
		layer.open({
        	type: 2
			, title: '消费数据'
			, shade: 0.2
			, shadeClose: true
			, id: 'viewRetail_dialog'
			, area: ['96%', height]
			, content: ['{{ urlfor "RetailController.View"}}?ret_id='+id]
			, anim: 1 //动画类型
		});
		return false;
	}
	//打印
	function viewPrints(id) {
		$.post('{{ urlfor "RetailController.Printer" }}/'+id, function(j){
			if(j.code == 1) {
				layer.msg(j.msg);
				return false;	
			}
			createRetailPrinter(j.data);
		}, 'json');
	}
</script>